package cn.fanyamin.action;

import org.apache.commons.lang.StringUtils;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private String username;
	private String password;
	public void setUsername(String username) {
		this.username = username;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getUsername() {
		return username;
	}
	public String getPassword() {
		return password;
	}
	
	public String execute() {
		if("walter".equals(this.username) && "pass".equals(this.password)) {
			return ActionSupport.SUCCESS;
		}
		return ActionSupport.ERROR;
	}
	
	public void validate() {
		super.validate();
		if(StringUtils.isBlank(this.username)) {
			this.addFieldError("username", "username is blank");
		}
		
		if(StringUtils.isBlank(this.password)) {
			this.addFieldError("password", "passwor is blank");
			
		}
	}
}
